﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Tailoring
{
    public partial class frmLogon : Form
    {
       
        bool a;

        public bool A
        {
            get { return a; }
            set { a = value; }
        }
        public frmLogon()
        {
            InitializeComponent();
        }
        public Boolean login()
        {
            Boolean a = false;
            if (txtuser.Text != "" & txtpass.Text != "")
            {
                string queryText = "SELECT Count(*) FROM tbllogin " +
                                   "WHERE username = @Username AND pass = @Password";
                using (SqlConnection cn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true"))
                using (SqlCommand cmd = new SqlCommand(queryText, cn))
                {
                    cn.Open();
                    cmd.Parameters.AddWithValue("@Username", txtuser.Text);  // cmd is SqlCommand 
                    cmd.Parameters.AddWithValue("@Password", txtpass.Text);
                    int result = (int)cmd.ExecuteScalar();
                    if (result > 0)
                    {
                        frmmainmdi mdi = new frmmainmdi();
                        a = true;
                        mdi.Userlbin.Text = txtuser.Text;
                        //mdi.login();

                        this.Close();

                        
                    }
                    else
                        MessageBox.Show("User Not Found!");
                }

            }
            return a;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmmainmdi mdi = new frmmainmdi();
            login();
            //this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            txtpass.Text = "";
            txtuser.Text = "";
            frmmainmdi mdi = new frmmainmdi();
            
            this.Close();


        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frmusercontrol user = new frmusercontrol();
            user.ShowDialog();
        }

    }
}
